﻿//2014-02-26
using System;
using System.Web;
using PSS.BLL.ReportManage.PurchasingReport;
using PSS.Entity.ReportManage.PurchasingReport;
using PSS.Utility;

namespace PSS.WebSite.Service
{
    /// <summary>
    /// ReportManageHandler 的摘要说明
    /// </summary>
    public class ReportManageHandler : IHttpHandler
    {

        private readonly InitPurDetailsReportBLL _initPurDetailsReportBll = new InitPurDetailsReportBLL();

        public void ProcessRequest(HttpContext context)
        {
            try
            {
                var action = StrRequest.GetQueryString("action");
                if (string.IsNullOrEmpty(action)) return;
                var method = this.GetType().GetMethod(action);
                if (method == null) return;
                object[] parameters = { context };
                method.Invoke(this, parameters);
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("程序错误：" + ex.Message);
            }
        }

        #region 采购报表

        #region 采购明细报表
        public void GetInitPurDetailsReportList(HttpContext context)
        {
            try
            {
                var qcmodel = new InitPurDetailsReportQcEntity
                {
                    DocDateFrom = context.Request["DocDateFrom"],
                    DocDateEnd = context.Request["DocDateEnd"],
                    SortField = context.Request["sortField"],
                    SortOrder = context.Request["sortOrder"]
                };
                var json = _initPurDetailsReportBll.GetInitPurDetailsReportList(qcmodel);
                context.Response.Write(json);
                context.Response.End();
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        public void ExportInitPurDetailsReport(HttpContext context)
        {
            try
            {
                var qcmodel = new InitPurDetailsReportQcEntity
                {
                    DocDateFrom = context.Request["DocDateFrom"],
                    DocDateEnd = context.Request["DocDateEnd"]
                };
                var dt = _initPurDetailsReportBll.ExportInitPurDetailsReport(qcmodel);
                if (dt.Rows.Count <= 0) return;
                const bool specificTime = false;
                dt.Columns[0].ColumnName = "单据日期";
                dt.Columns[1].ColumnName = "单据编号";
                dt.Columns[2].ColumnName = "业务类别";
                dt.Columns[3].ColumnName = "供应商编号";
                dt.Columns[4].ColumnName = "供应商名称";
                dt.Columns[5].ColumnName = "商品编号";
                dt.Columns[6].ColumnName = "商品名称";
                dt.Columns[7].ColumnName = "规格型号";
                dt.Columns[8].ColumnName = "单位";
                dt.Columns[9].ColumnName = "仓库";
                dt.Columns[10].ColumnName = "数量";
                dt.Columns[11].ColumnName = "单价";
                dt.Columns[12].ColumnName = "采购金额";
                if (dt.Rows.Count > 0)
                {
                    ExcelHelper.ExportByWeb(dt, DateTime.Now.ToShortDateString() + "采购明细报表", DateTime.Now.ToShortDateString() + "采购明细报表.xls", specificTime);
                }
            }
            catch (Exception ex)
            {
                EventsLog.WriteLog("ErrorInfo" + ex.Message);
            }
        }
        #endregion

        #endregion

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}